/**
 * 
 */
package com.effectiv.gooruda.security;

import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import com.effectiv.gooruda.domain.Tenant;

/**
 * @author Dhrubo
 * 
 */
public abstract class SecurityUtil {

	public static Tenant getTenant() {
		SecurityContext ctx = SecurityContextHolder.getContext();
		SimpleUserDetails userDetails = null;
		Tenant tenant = null;
		Object o = ctx.getAuthentication().getPrincipal();

		if (o instanceof SimpleUserDetails) {
			userDetails = (SimpleUserDetails) o;
		}

		if (userDetails != null) {
			tenant = userDetails.getTenant();
		}
		return tenant;
	}

}
